<?php


namespace app\api\controller\v1;
use app\common\model\Members as MembersModel;
use app\common\model\Notice;

class Mine extends Base
{
    //我的初始化
    public function mineInit(){
        $user_id = $this->checkUserToken();
        $data = MembersModel::field('id,nickname,mobile,image_uri')->get($user_id);
        return j(0,'获取我的初始化数据成功',[
            'data' => $data
        ]);
    }
    //个人信息
    public function personalInfo(){
        $user_id = input('user_id');
//        $user_id = $this->checkUserToken();
        $data = MembersModel::field('id,nickname,mobile,image_uri')->get($user_id);
        return j(0,'获取个人信息数据成功',[
            'data' => $data
        ]);
    }
    //修改手机号
    public function updateMobile(){
        $user_id = $this->checkUserToken();
        $mobile  = input('mobile');
        if (empty($mobile)){
            return j(1,'手机号不能为空');
        }
        $data = MembersModel::get($user_id);
        $data->mobile = $mobile;
        if ($data->save()){
            return  j(0,'成功');
        }else{
            return  j(1,'失败');
        }
    }

    public function UpdateNickName(){
        $userId = $this->checkUserToken();
        $nickName = input('nickname');
        $data = MembersModel::get($userId);
        $data->nickname = $nickName;
        if ($data->save()){
            return j(0, '成功');
        }
        return j(1, '失败');
    }
    public function UpdateHeadImg(){
        $userId = $this->checkUserToken();
        $head_img = input('head_img');
        $img = attach_uri($head_img);
        $data = MembersModel::get($userId);
        $data->image_uri = $img;
        if ($data->save()){
            return j(0, '成功');
        }
        return j(1, '失败');
    }

}